import {connect, useNavigate, useLocation } from "umi";
import CheckListWithSearch from "@/components/CheckListWithSearch";
import "./project.less"

const ProjectPage = ({dispatch, project}) => {
    const navigate = useNavigate();
    const { state } = useLocation();

    dispatch({
        type: 'project/setOrgId',
        payload: {
            value: state.orgId
        }
    });

    const handleCheck = (value) => {
        console.log(value)
        if (value) {
            const proj = value[0];
            navigate("/", {
                state: {
                    project: {
                        id: proj.id,
                        name: proj.name,
                        code: proj.code
                    },
                }
            })
        }

    }
    const handleSearch = (v) => {
        dispatch({
            type: 'project/setSearchText',
            payload: {
                value: v
            }
        });
    }

    return (
        <CheckListWithSearch data={project.list} searchText={project.searchText} onCheck={v => handleCheck(v)}
                             onSearch={v => handleSearch(v)}/>
    );
};

export default connect(project => project)(ProjectPage);
